package neo

import com.antgroup.tugraph.ogm.config.Configuration
import com.antgroup.tugraph.ogm.driver.Driver
import com.antgroup.tugraph.ogm.drivers.rpc.driver.RpcDriver
import com.antgroup.tugraph.ogm.session.SessionFactory
import com.gitee.ixtf.core.J

// 启动driver
private val driver: Driver =
    RpcDriver().apply {
      val databaseUri = "list://127.0.0.1:9090"
      val username = "admin"
      val password = "iNO^oSY#J2KXAHEf"
      // 配置
      val builder =
          Configuration.Builder()
              .uri(databaseUri)
              .verifyConnection(true)
              .credentials(username, password)
      configure(builder.build())
    }

fun main() {
  // 开启session
  val sessionFactory = SessionFactory(driver, "test")
  val session = sessionFactory.openSession()

  val jokes =
      Movie().apply {
        id = J.objectId()
        title = "Jokes"
        released = 1990
      }
  session.save(jokes)

  val speed =
      Movie().apply {
        id = J.objectId()
        title = "Speed"
        released = 2019
      }

  val alice =
      Actor().apply {
        id = J.objectId()
        name = "Alice Neeves"
      }
  alice.actsIn(speed)
  session.save(speed)
}
